import './style.css'
import { Button } from 'antd'
import { useEffect } from 'react'
import { getUrlSearchParams } from '@hs-admin/utils'

const LoginPage = () => {
  const outsideLogin = () => {
    const query = {
      client_id: import.meta.env.VITE_CLIENT_ID,
      redirect_uri: window.location.href,
      scope: 'user.profile',
      response_type: 'code',
      from: '产业预警通'
    }
    const urlQuery = new URLSearchParams(query).toString()
    window.location.href = `${import.meta.env.VITE_USER_CENTER_URL}#/authorize?${urlQuery}`
  }
  useEffect(() => {
    if (!getUrlSearchParams('fail')) {
      outsideLogin()
    }
  }, [])

  return (
    <div className="login-wrapper">
      <div className="system-title">
        <h1>产业预警通</h1>
      </div>
      <div className="login-form">
        <h2>欢迎登录</h2>
        <Button type="primary" onClick={outsideLogin}>
          第三方登录
        </Button>
      </div>
    </div>
  )
}
export default LoginPage
